import Vue from "vue";
import VueRouter from "vue-router";
import Login from "@/views/Login";
import Main from "@/views/Main";
import Estores from "@/views/Estores";
import Orders from "@/views/Orders";
import Products from "@/views/Products";

Vue.use(VueRouter);

const routes = [
    {
        path: "/",
        redirect: "/login",
    },
    {
        path: "/login",
        name: "Login",
        component: Login,
    },
    {
        path: "/main",
        redirect: "/main/estores",
    },
    {
        path: "/main",
        name: "Main",
        component: Main,
        children: [
            {
                path: "estores",
                name: "Estores",
                component: Estores,
            },
            {
                path: "orders",
                name: "Orders",
                component: Orders,
            },
            {
                path: "products",
                name: "Products",
                component: Products,
            },
        ],
    },
];

const router = new VueRouter({
    routes,
});

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch((err) => err);
};

export default router;
